<?php
include 'conn_mysql.php';

include 'conn_login.php';


//判读是否是支付成功后的回调页面，若是则扣除相应驴币，设置订单为已支付状态
$ke_lvbi=$_REQUEST['ke_lvbi'];
$is_zhifu=$_REQUEST['is_zhifu'];
$order_id=$_REQUEST['order_id'];
if($is_zhifu==1&&$order_id){

        //参加活动的人数
		$sql="SELECT count(*) FROM `fu_user` WHERE id='$order_id'";
		$query = mysql_query($sql);
		$row2 = mysql_fetch_array($query);
		$peo_num=$row2[0]?$row2[0]:0;
		$fanduos=0;

		//获取用户应得的驴币id_difang
		$sql="select * from `lvyou_difang_info` where id='$id_difang'";
		$query = mysql_query($sql);
		while($row = mysql_fetch_array($query)){
			$fanduos=$row['fanduos'];
		}
		$sum_fanduo=$peo_num*$fanduos;


	    /*****************zhsk分享赠送驴币**********************/
		$sql="SELECT share_id,status,user_pid FROM `ecs_share_url` WHERE openid='".$openid."' and id_difang='$id_difang'";
	    $query = mysql_query($sql);

	    $row = mysql_fetch_array($query);
	    $share_id=$row[0];
	    $status=$row[1];
	    $user_pid=$row[2];
	    if($user_pid)
	    {
	    	$sum_fanduo=$sum_fanduo-($peo_num*10);
	    }
	    /*****************zhsk分享赠送驴币**********************/

	    if( $sum_fanduo>0)
	    {
	    	echo "<SCRIPT>alert('恭喜您成功支付订单，系统赠送您 $sum_fanduo 驴币奖励');</SCRIPT>";
	    }
	    else
	    {
	    	echo "<SCRIPT>alert('恭喜您成功支付订单');</SCRIPT>";
	    }



	  
	


	

}

//已经进入到订单提交页，开启返回订单页按钮
$_SESSION['is_xiugai']=1;
$_SESSION['is_xiugai']='';//有了我的旅行列表，返回订单页按钮从新关闭

//查询申请人用户信息
$sql="select * from ecs_users where openid='".$openid."'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)){
	$id=$row['id_self'];
	$user_name=$row['user_name'];
	$real_name=$row['real_name'];
	$phone=$row['mobile_phone'];   
	$pay_points=$row['pay_points'];//持有驴币数
	$sex=$row['sex'];              //性别
	$shenfen_ID=$row['shenfen_ID'];//身份证
}
//查询订单信息
$sql="select * from main_user where id_self='".$id_main."'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)){
	$textarea=$row['textarea'];//订单备注
	$num=$row['num'];          //单房差数量
	$banqi=$row['banqi'];      //报名班期
	$is_zhifu=$row['is_zhifu'];//是否支付
	
}
//查询地方信息
$sql="SELECT * FROM `lvyou_difang_info` WHERE id='".$id_difang."'";
$query = mysql_query($sql);

$error_mes='';
while($row = mysql_fetch_array($query)){
	$biaoti=$row['biaoti'];
	$jitian=$row['jitian'];
	$fanduos=$row['fanduos'];
	$picture_lujing=$row['picture_lujing'];
	$danfangcha=$row['danfangcha'];
	
	if($banqi==$row['banqi1']){
		$chengren=$row['chengren1'];
		$ertong=$row['ertong1'];
	}
	else if($banqi==$row['banqi2']){
		$chengren=$row['chengren2'];
		$ertong=$row['ertong2'];
	}
	else if($banqi==$row['banqi3']){
		$chengren=$row['chengren3'];
		$ertong=$row['ertong3'];
	}
	else if($banqi==$row['banqi4']){
		$chengren=$row['chengren4'];
		$ertong=$row['ertong4'];
	}
	else if($banqi==$row['banqi5']){
		$chengren=$row['chengren5'];
		$ertong=$row['ertong5'];
	}
	else if($banqi==$row['banqi6']){
		$chengren=$row['chengren6'];
		$ertong=$row['ertong6'];
	}
	else
	{
		$error_mes='该活动的当前班期已删除！';
	}
}
$monkey=0;




?>

<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no">
    <title>驴行天下</title>
    <link href="bootstrap.min.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<body onLoad="adaptive()">
<!--header-->
<div class="header_title">
	<!--<p>【贵州精华】2016全年贵州：西江千户苗寨-朗德上寨-荔波小七孔-黄果树瀑布-青岩古镇，奇山秀水、苗家风情之旅6日团</p>-->
	<p><a href="muban_1.php?id_difang=<?php echo $id_difang;?>"><?php echo $biaoti;?></a></p><!--旅游项目标题-->
</div>
<!--plate-->
<div class="plate">
	<h1>订单详情</h1>
<!--    <div class="plate_detail">
    	<div><h1>手机号：</h1><h2><?php echo $phone;?></h2></div>
    </div>
    <div class="plate_detail">
    	<div><h1>身份证：</h1><h3><?php echo $shenfen_ID;?></h3></div>
    </div>
    <div class="plate_detail">
    	<div><h1>费&nbsp;&nbsp;&nbsp;&nbsp;用：</h1><h2><?php echo $jiage;?>.00&nbsp;元</h2>
    	</div>
    </div>-->
<?php 

if($error_mes)
{
	echo "<SCRIPT>alert('".$error_mes."');window.location.href='log_gerenzhongxing1.php?bigtype=2';</SCRIPT>";
	exit;
}

$monkey=0;


 ?>	
	
	<?php
	//读取随行用户信息
	$sql="select * from fu_user where id='".$id_main."'";
	$query = mysql_query($sql);
	while($row = mysql_fetch_array($query)){
	?>
		<div class="line_short"></div>
		<div class="plate_detail">
			<div><h1>姓&nbsp;&nbsp;&nbsp;&nbsp;名：</h1><h2><?php echo $row['name'];?>&nbsp;&nbsp;
			<?php 
			if($row['choose']==1){
				echo "男成人";
				$jiage=$chengren;
			}
			else if($row['choose']==2){
				echo "女成人";
				$jiage=$chengren;
			}
			else if($row['choose']==3){
				echo "儿童";
				$jiage=$ertong;
			}
			else {
				echo "男成人";
				$jiage=$chengren;
			}

			?></h2></div>
		</div>
		<div class="plate_detail">
			<div><h1>手机号：</h1><h2><?php echo $row['phone'];?></h2></div>
		</div>
		<div class="plate_detail">
			<div><h1>身份证：</h1><h3><?php echo $row['idcode'];?></h3></div>
		</div>
		<div class="plate_detail">
			<div><h1>费&nbsp;&nbsp;&nbsp;&nbsp;用：</h1><h2><?php echo $jiage;?>.00&nbsp;元</h2>
				<?php if($is_zhifu==0){ ?>
				<a href="" class="plate_change" onClick="del_suixingyouke('<?php echo $row['id_fu'];?>');" id="shanchu1">删除</a>
				<a href="add.php?id_fu=<?php echo $row['id_fu'];?>" class="plate_change" id="xiugei2">修改</a>
			  <?php } ?>
			</div>
		</div>
	<?php $monkey=$jiage+$monkey; }?>
	<div class="line_short"></div>
	<?php if($is_zhifu==0){ ?>
        <a><div class="plate_line_add" onClick="window.location.href='chose_user.php'" id="tianjia1"><div>+</div><h2>选择游客</h2></div></a>
		<a><div class="plate_line_add" onClick="window.location.href='add.php'" id="tianjia1"><div>+</div><h2>添加游客</h2></div></a>
	<?php } ?>
	

	<div class="line_short"></div>
    <div class="plate_detail">
    	<div><h4>全程单房差：</h4><h2>
		<?php
		if($num==0){
			echo 0;
		}else{
			echo $danfangcha.".00*$num";
			$monkey=$monkey+$danfangcha*$num;
		}
		?>

		</h2>
       <?php if($is_zhifu==0){ ?>
		<a href="xiugeidanfangcha.php" class="plate_change" id="xiugei3">修改</a>
		<?php } ?>
	</div>
    </div>
	<div class="line_short"></div>
	
	
    <div class="plate_detail">
    	<div><h4>备注：</h4><h2><?php echo $textarea;?></h2>
		<?php if($is_zhifu==0){ ?>
    		<a href="xiugei_mian.php" class="plate_change" id="xiugei4">修改</a>
    	<?php } ?>
    </div>
    </div>
		
    <div class="line_short"></div>
    <div class="plate_detail" id="plate_detail">
    	<div><h1>结&nbsp;&nbsp;&nbsp;&nbsp;算：</h1><h2><?php echo $monkey;
    	if($is_zhifu==0){
		    //该比订单所需支付的钱 保存入数据库
			$sql="update `main_user` set zhifu_monkey='$monkey' where id_self='$id_main'";
			$query = mysql_query($sql);
		 }
		?>&nbsp;元</h2></div>
    </div>
</div>
<?php
//判断该笔订单是否支付成功
if((string)$is_zhifu==(string)0){//未支付
?>
<div class="button"><input type="submit" value="支&nbsp;&nbsp;付" onClick="pay();"></div>
<?php }else if($is_zhifu==1 ){//已支付?>
<div class="button"><input type="submit" value="已支付"></div>
<?php }else if($is_zhifu==2 ){//已取消?>
<div class="button"><input type="submit" value="已取消"></div>
<?php }?>

<div style="width:100%;height:50px;"></div>
<!--底部返回首页个人中心菜单-->
<div style="box-shadow:0px 0px 2px 0px #bbb;width:100%;height:50px;background-color:#FEFEFE;position:fixed;z-index:998;bottom:0px;">
	<div style="float:left;width:33%;height:50px;" onClick="window.location.href='lvyou_list.php';">
		<img style="float:left;width:17%;height:20px;margin:7px 0 0 47%;" src="picture1/qvnawan_hong.png"></img>
		<a style="clear:left;float:left;color:#E50011;font-family:微软雅黑;font-size:14px;margin:0 0 0 37%;">去哪玩</a>
	</div>
	<div style="float:left;width:33%;height:50px;" onClick="window.location.href='http://haining.365jinbi.com/lxtx/mobile/index.php?m=default&c=index&a=index';">
		<img style="float:left;width:17%;height:20px;margin:7px 0 0 30%;" src="picture1/meihaohuo_hui.png"></img>
		<a style="clear:left;float:left;color:#AAAAAB;font-family:微软雅黑;font-size:14px;margin:0 0 0 21%;">买好货</a>
	</div>
	<div style="float:left;width:33%;height:50px;" onClick="window.location.href='http://haining.365jinbi.com/lxtx/mobile/index.php?m=default&c=user&a=index';">
		<img style="float:left;width:17%;height:20px;margin:7px 0 0 30%;" src="picture1/lvyouhui_hui.png"></img>
		<a style="clear:left;float:left;color:#AAAAAB;font-family:微软雅黑;font-size:14px;margin:0 0 0 21%;">驴游会</a>
	</div>
</div>

</body>
<script>
function adaptive(){
	//若订单已支付，利用js，将修改按钮全部隐藏
	<?php if($is_zhifu!=0){?>
	document.getElementById('xiugei1').style.display ='none';
	if(document.getElementById("xiugei2")!=undefined){
		document.getElementById('xiugei2').style.display ='none';
	}
	document.getElementById('xiugei3').style.display ='none';
	document.getElementById('xiugei4').style.display ='none';
	document.getElementById('tianjia1').style.display ='none';
	if(document.getElementById("shanchu1")!=undefined){
		document.getElementById('shanchu1').style.display ='none';
	}
	
	<?php }?>
}
function intOnly(){
  var codeNum=event.keyCode;
  if(codeNum==8||codeNum==37||codeNum==39||(codeNum>=48&&codeNum<=57)){
    event.returnValue=codeNum;
  }else{
    event.returnValue=false;
  }
}

function del_suixingyouke(id_fu){
	var url="getmessage_all.php?bigtype=3";
	url=url+"&id_fu="+id_fu;
	url=url+"&id=<?php echo $_REQUEST['id'];?>";

	$.ajax({
		type:"GET",
		url:url,
		dataType: "json",
		success: function(data){	
			if(data['code']==0001){
				window.location.href='index_pay.php';
			}else{
				
			}
		},
		error:function(){
		}
	});
}
<?php
//组装描述字符串
$miaoshu=$biaoti;//暂时使用旅游地方标题
?>
//支付  注：扣除驴币操作在支付的异步回调中执行
function pay(){
	<?php if($pay_points>0){ //用户持有驴币，询问是否用驴币代替现金支付?>
		var boo = confirm('系统检测到您当前拥有<?php echo $pay_points;?>驴币，是否使用驴币代替现金支付！');        
		if(boo){            
			 <?php if($pay_points>$monkey){?>
				alert('您持有的驴币数大于要支付的金额，系统将扣除相应驴币，并将订单价格设置为1分钱，请支付！');
				window.location.href='PHP/demo/js_api_call.php?id_main=<? echo $id_main;?>&monkey=<? echo 1;?>&miaoshu=<?php echo $miaoshu;?>&ke_lvbi=<?php echo $monkey;?>';
			 <?php }else{ ?>
				window.location.href='PHP/demo/js_api_call.php?id_main=<? echo $id_main;?>&monkey=<? echo ((int)$monkey-(int)$pay_points)*100;?>&miaoshu=<?php echo $miaoshu;?>&ke_lvbi=<?php echo $pay_points;?>';
			 <?php }?>
		}else{            
			 window.location.href='PHP/demo/js_api_call.php?id_main=<? echo $id_main;?>&monkey=<? echo $monkey*100;?>&miaoshu=<?php echo $miaoshu;?>&ke_lvbi=<?php echo 0;?>';     
		}
	
	<?php }else{ ?>
			window.location.href='PHP/demo/js_api_call.php?id_main=<? echo $id_main;?>&monkey=<? echo $monkey*100;?>&miaoshu=<?php echo $miaoshu;?>&ke_lvbi=<?php echo 0;?>'; 
	<?php } ?>
}
</script>
</html>



